package com.suning.sawp.service.branch;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.suning.framework.dal.client.DalClient;

@Service("branchRetStatisServiceMonth")
public class BranchRetStatisServiceMonth extends BranchRetStatisServiceBase implements BranchRetStatisService {

    @Autowired
    DalClient dalClient;

    /**
     * 月统计
     * 
     * @return
     */
    @Override
    public BranchRetStatis queryStatis(String storeCode, String[] categoryCodes, int offset) {
        //
        LocalDate localDate = new LocalDate().plusDays(offset);
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("months", localDate.getMonthOfYear());
        paramMap.put("storeCode", storeCode);
        if (!ArrayUtils.isEmpty(categoryCodes)) {
            paramMap.put("categoryCodes", Sets.newHashSet(categoryCodes));
        }
        List<BiStoreRetGdBranch429> branch429s = dalClient
                .queryForList("BranchRetStatisService.queryStatisMonthBranchs", paramMap, BiStoreRetGdBranch429.class);
        List<BiStoreBranch4RetGds> branch4s = dalClient.queryForList("BranchRetStatisService.queryStatisMonth",
                paramMap, BiStoreBranch4RetGds.class);
        return indexBranchRetGds(branch4s, branch429s);
    }
}
